import {
  GET_TOPSECTION_DATA, //轮播图
  GET_HOTSRECOMMEND_DATA, //热门演出
  GET_VIPSCHEDULAR_DATA, //VIP
  GET_PERFORMANCETYPE_DATA, //六大演出
  GET_TOURRECOMMEND_DATA, //巡回演出
  GET_TOPSHOPLIST_DATA, //大杂烩
  GET_SHOWLIST_DATA, //为你推荐
  GET_HEADSERCH_DATA, //搜索
  GET_CHASEARCH_DATA, //搜索框
  GET_HOTTHEATRE_DATA, //热门场馆
  GET_LISTHEAD_DATA, //列表
  GET_SHOWHEAD_DATA //show
} from "./actionType";

export const LOAD_TEST_DATA = "index/get_test_data";
export const SET_CURRENT_CITY = "index/set_current_city";

const loadGetTopSectionData = val => {
  //轮播图
  return {
    type: GET_TOPSECTION_DATA,
    val
  };
};
const loadGetHeadSerchData = val => {
  //搜索
  return {
    type: GET_HEADSERCH_DATA,
    val
  };
};
const loadGetChaSearchData = val => {
  //搜索框
  return {
    type: GET_CHASEARCH_DATA,
    val
  };
};
const loadGetToShopListData = val => {
  //大杂烩
  return {
    type: GET_TOPSHOPLIST_DATA,
    val
  };
};
const loadHotsRecommendData = val => {
  //热门演出
  return {
    type: GET_HOTSRECOMMEND_DATA,
    val
  };
};
const loadVipHomeSchedularData = val => {
  //VIP
  return {
    type: GET_VIPSCHEDULAR_DATA,
    val
  };
};
const loadGetHotTheatreData = val => {
  //热门场馆
  return {
    type: GET_HOTTHEATRE_DATA,
    val
  };
};
// 梁港彬
const loadGetPerformanceTypeData = val => {
  //六大演出
  return {
    type: GET_PERFORMANCETYPE_DATA,
    val
  };
};
const loadGetTourRecommendData = val => {
  //巡回演出
  return {
    type: GET_TOURRECOMMEND_DATA,
    val
  };
};
const loadGetShopListData = val => {
  //为你推荐
  return {
    type: GET_SHOWLIST_DATA,
    val
  };
};
const loadGetListHeadData = val => {
  //列表
  return {
    type: GET_LISTHEAD_DATA,
    val
  };
};
const loadShowData = val => {
  //show
  return {
    type: GET_SHOWHEAD_DATA,
    val
  };
};
var poxy = "/apis";
//郭立鹏    城市
export const loadIndexCityDate = callback => {
  fetch(poxy + "/city/city/getSortedCityList?version=6.0.8&referer=2", {
    method: "GET"
  })
    .then(data => {
      return data.json();
    })
    .then(res => {
      callback(res);
    });
};

//郭立鹏    搜索
export const loadGetHeadSerchDataAsync = (dispatch, params) => {
  fetch(poxy + `/Show/Search/getHotWord?version=6.0.8&referer=2`, {
    method: "GET"
  })
    .then(data => {
      return data.json();
    })
    .then(res => {
      dispatch(loadGetHeadSerchData(res));
    });
};

//郭立鹏    搜索框
export const loadGetChaSearchDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `/Show/Search/getShowList?keywords=${params.keywords}&page=1&sort_type=1&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      dispatch(loadGetChaSearchData(res.data));
    });
};

//郭立鹏  轮播
export const loadIndexTopSectionDate = (dispatch, params) => {
  fetch(
    poxy +
      `home/index/getClassifyHome?city_id=${params.city_id}&abbreviation=${params.abbreviation}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      dispatch(loadGetTopSectionData(res.data));
    });
};

//郭立鹏  大杂烩
export const loadGetToShopListDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `home/index/getClassifyHome?city_id=${params.city_id}&abbreviation=${params.abbreviation}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      dispatch(loadGetToShopListData(res.data));
    });
};

//张晓东   热门演出
export const loadHotsRecommendDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `/home/index/getHotsRecommendList?city_id=${params.city_id}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data.hots_show_list;
      dispatch(loadHotsRecommendData(val));
    });
};
// 晓东   巡回演出
export const loadGetTourRecommendDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `/home/index/getTourRecommendList?city_id=${params.city_id}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data;
      // console.log(val);
      dispatch(loadGetTourRecommendData(val));
    });
};
//Vip 接口  刘杰
export const loadVipHomeSchedularDataAsync = dispatch => {
  fetch(poxy + `vip/index/getVipHomeSchedular?version=6.0.8&referer=2`, {
    method: "GET"
  })
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data;
      dispatch(loadVipHomeSchedularData(val));
    });
};

//热门场馆  刘杰
export const loadGetHotTheatreDataAsync = dispatch => {
  fetch(poxy + `/home/index/getHotTheatre?version=6.0.8&referer=2`, {
    method: "GET"
  })
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data;
      dispatch(loadGetHotTheatreData(val));
    });
};
// 梁港彬 演出种类
export const loadGetPerformanceTypeDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `home/index/getFloorShow?city_id=${params.city_id}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data;
      dispatch(loadGetPerformanceTypeData(val));
    });
};
// 郭立鹏 为你推荐
export const loadGetShopListDataAsync = (dispatch, params) => {
  fetch(
    poxy +
      `/Show/Search/getShowList?city_id=${params.city_id}&page=1&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      var val = res.data;
      dispatch(loadGetShopListData(val));
    });
};
//list  郭立鹏
export const loadGetListHeadDataAsync = callback => {
  fetch(poxy + `theatre/index/getTheatreList?page=1&version=6.0.8&referer=2`, {
    method: "GET"
  })
    .then(data => {
      return data.json();
    })
    .then(res => {
      callback(loadGetListHeadData(res.data));
    });
};
//show  郭立鹏
export const loadShowDataAysnc = (dispatch, params) => {
  fetch(
    poxy +
      `/Schedule/Schedule/getScheduleInfo?schedular_id=${params.schedular_id ||
        105436}&version=6.0.8&referer=2`,
    {
      method: "GET"
    }
  )
    .then(data => {
      return data.json();
    })
    .then(res => {
      // console.log(res.data);
      dispatch(loadShowData(res.data));
    });
};
